package szhu.hcc.umbc.crowdsourcing.quality.core;

import java.util.*;

/**
 * An enhanced version to include gold standard into algorithm design.
 *
 * @author szhu1@umbc.edu
 */
public class QualityJudgingGoldStandardCoreImpl extends QualityJudgingGamingCoreImpl {

    private int goldStandThreshold = 1;

    public QualityJudgingGoldStandardCoreImpl(List<RawData> Logs, int goldStandThreshold) {
        super(Logs);
        this.goldStandThreshold = goldStandThreshold; //(int) (goldStandThreshold * Logs.size());
        workerBlackList = new HashMap<>();
    }

    @Override
    protected void saveWorkerBlackList(
            List<Integer> trainingTaskids, boolean isTraining, double[][] params, boolean isStrict) {
        for (int i = 0; i < rawLogs.size(); i += MAX_WORKER_PER_TASK) {
            RawData rawData = rawLogs.get(i);
            List<Double> taskNatures = rawData.taskNatures;
            // All tasks in same group have the same natures, so we can get thresholds without knowing user efforts
            double[] userEffortThresholds = this.computeExpectedValueWithRegressionParams(taskNatures, params);
            int taskId = i / MAX_WORKER_PER_TASK;
            for (int j = 0; j < MAX_WORKER_PER_TASK; j++) {
                if (isTraining && !trainingTaskids.contains(taskId)) {
                    continue;
                }
                if (!isTraining && trainingTaskids.contains(taskId)) {
                    continue;
                }
                RawData data = rawLogs.get(i + j);
                // TODO: extend to multiple dimensions of quality classification by enlarging this result matrix
                if (data.quality < 0 && isTraining) {
                    saveWorkerBlackListToMap(data.workerId);
                }
            }
        }
    }

    @Override
    protected boolean inWorkerBlackList(String workerId) {
        return workerBlackList.containsKey(workerId) && (workerBlackList.get(workerId) >= goldStandThreshold);
    }
}
